<template>
  <div class="supplier_display_title">
    <div class="w1200 supplier_display_title_box">
<!--      <img src="@/assets/images/supplierDisplayCenter/logo.png" @click="toHome" />-->
      <img :src="portalLogoUrl" @click="toHome" />
      <a-input-group class="supplier_display_title_box_search" compact size="large">
        <a-select v-if="showSearchType" v-model="searchForm.searchType">
          <a-select-option value="1">
            产品
          </a-select-option>
          <a-select-option value="2">
            供应商
          </a-select-option>
        </a-select>
        <a-input-search style="flex: 1;" v-model="searchForm.searchWords" @search="toSearch">
          <a-button type="primary" class="search" slot="enterButton" icon="search">
            {{ searchText }}
          </a-button>
        </a-input-search>
      </a-input-group>
      <div>
        <a-button type="primary" v-if="role == 'DATA_REQUESTER'" ghost size="large" style="font-size: 14px;"
          @click="toAddInquiry">立即发布商机信息</a-button>
      </div>
    </div>
  </div>
</template>

<script>
import { appConfig } from '@/config/app'
import storage from '@/utils/storage'

export default {
  name: "TitleBox",
  data() {
    return {
      searchForm: {
        searchWords: '',
        searchType: '1'
      },
      searchText: '搜索',
      showSearchType: true,
      isLogin: storage.session.get('isLogin') && storage.session.get('authToken'),
      role: this.$store.state.role,
      portalLogoUrl: ''
    }
  },
  watch: {
    newData: {

      handler(val) {
        console.log('------')

        this.role = val

      },

    },
    '$route.query': {
      handler(val) {
        console.log('------222',val)
      },
      deep:true
    }

  },
  computed: {
    newData() {
      console.log('------')
return this.$store.state.role

},
  },
  created() {
    console.log(this.$route)
    this.searchForm.searchWords = this.$route.query.searchWords
    this.searchForm.searchType = this.$route.query.searchType ? this.$route.query.searchType : '1'
    console.log(this.$router)
    console.log('portalSettingsInfo',storage.session.get('portalSettingsInfo'))
    let portalSettingsInfo = storage.session.get('portalSettingsInfo')
    this.portalLogoUrl = portalSettingsInfo.portalLogoUrl
    this.portalBackendLogoUrl = portalSettingsInfo.portalBackendLogoUrl // 后台
    this.portalBackendUrl = portalSettingsInfo.portalBackendUrl // 登录logo
    this.favicon = portalSettingsInfo.favicon // 后台
    this.loginBackgroundUrl = portalSettingsInfo.loginBackgroundUrl // 登录页背景
  },
  methods: {

    toHome() {
      // if (this.$route.name !== '/') {
      //   this.$router.push('/supplierDisplayCenter')
      // }
    },
    toSearch() {

      if (this.searchForm.searchType == 2){
        if (this.$route.path === '/supplierList' ){

        }else {
          this.$router.push({
            path: '/supplierList',
            query: {
              ...this.searchForm
            }
          })
        }
      }

      // if (this.$route.path === '/supplierSearch' || this.$route.path === '/supplierHot' || this.$route.path === '/supplierLatestNotice') {
      //   this.$eventHub.$emit('onSearch', this.searchForm)
      // } else {
      //   if(this.searchForm.searchType == 3){
      //     this.$router.push({
      //       path: '/supplierLatestNotice',
      //       query: {
      //         ...this.searchForm
      //       }
      //     })
      //   }else
      //   this.$router.push({
      //     path: '/supplierSearch',
      //     query: {
      //       ...this.searchForm
      //     }
      //   })
      // }
    },
    toAddInquiry() {
      // if (this.isLogin) {
      //   this.$router.push('/nicheM_add')
      // } else {
      //   this.toLogin()
      // }
    },
    toLogin() {
      window.location.href = appConfig.purLoginUrl
    }
  },

}
</script>

<style scoped lang="scss">
$colorPrimary: #0078FE;

.supplier_display_title {
  width: 100%;
  background-color: white;

  &_box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 110px;

    img {
      height: 56px;
    }

    &_search {
      width: 500px;
      display: flex !important;

      .ant-select {
        width: 80px;
      }

      >>>.ant-select-selection {
        border-color: $colorPrimary;
        font-size: 14px;
      }

      /deep/ .ant-input-group-addon {
        padding: 3px;
        border: 1px solid $colorPrimary;
        border-left: none;
        background: #ffffff;
      }

      /deep/ button {
        background-color: rgba($colorPrimary, .1);
        color: $colorPrimary;
        font-size: 14px;
        height: 32px;
        border-radius: 4px !important;
        border: none;
      }

      /deep/ input {
        border-color: $colorPrimary;
        font-size: 14px;
      }
    }

    /deep/ .ant-select-selection__rendered {
      line-height: 38px !important;
    }
  }
}
</style>
